package com.mdd.front.controller.course;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.course.ICourseCommentService;
import com.mdd.front.validate.CourseCommentParam;
import com.mdd.front.validate.PageParam;
import com.mdd.front.vo.course.CourseCommentListVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 评论管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/course/comment")
public class CourseCommentController {

    @Resource
    ICourseCommentService iCourseCommentService;

    /**
     * 评论列表
     *
     * @author panweiliang
     * @param courseId 课程id
     * @return Object
     */
    @GetMapping("/list")
    public Object list(@Validated PageParam pageParam,
            @RequestParam("courseId") Integer courseId) {
        PageResult<CourseCommentListVo> list = iCourseCommentService.list(pageParam, courseId);
        return AjaxResult.success(list);
    }

    /**
     * 评论删除
     *
     * @author panweiliang
     * @param courseCommentParam 参数
     * @return Object
     */
    @PostMapping("/del")
    public Object del(@Validated(value = CourseCommentParam.delete.class) @RequestBody CourseCommentParam courseCommentParam) {
        iCourseCommentService.del(courseCommentParam.getId());
        return AjaxResult.success();
    }

    /**
     * 评论添加
     *
     * @author panweiliang
     * @param courseCommentParam 参数
     * @return Object
     */
    @PostMapping("/add")
    public Object add(@Validated(value = CourseCommentParam.create.class) @RequestBody CourseCommentParam courseCommentParam) {
        courseCommentParam.setUserId(LikeFrontThreadLocal.getUserId());
        iCourseCommentService.add(courseCommentParam);
        return AjaxResult.success();
    }

}
